package com.example.demo;

import com.example.demo.model.Emp;
import org.joda.money.Money;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface EmpRepository extends CrudRepository<Emp,Long> {
    @Transactional(rollbackFor = Exception.class)
    @Modifying
    @Query("update Emp set name=?1 where id=?2")
    void editEmp(String name,Long id);

    List<Emp> findEmpsByNameLike(String name);

    //@Query("from Emp where name=:name and job=:job and salary=:salary")
    List<Emp> findEmpsByNameEqualsAndJobEqualsAndSalaryEquals(String name, String job, Money salary);

    @Query("from Emp where name=:name and job=:job and salary=:salary")
    List<Emp> findEmps(@Param("name")String name, @Param("job")String job, @Param("salary")Money salary);

    @Query("from Emp where name=:title and job=:job and salary=:salary")
    List<Emp> findEmployees(String title, String job, Money salary);
}
